"""
6.下拉框操作.py
导入下拉框类:
from selenium.webdriver.support.select import Select
定位下拉框元素
ele = driver.find_element(By.ID,"role")
select_object =  Select(ele)
select_object.select_by_index()  通过索引值 选择下拉框

# 定位下拉框
1.使用 Select 类进行定位
    ele = driver.find_element(By.ID, "role")
    # 生成下拉框对象
    select_object = Select(ele)
    # 1.通过 select_by_index() 选择下拉框的值.
    # select_object.select_by_index(8)
    # 2.通过 value 值进行选择:
    # select_object.select_by_value("support")
    # 3.通过选项的文本值进行选择
    select_object.select_by_visible_text("技术支持")

2.定位到下拉框元素 .send_keys()
    ele = driver.find_element(By.ID, "role")
    ele.send_keys("技术支持")
2.定位到下拉框元素 进行点击
    driver.find_element(By.ID, "role").click()
    driver.find_element(BY.XX ,下拉框选项).click()
"""
from selenium.webdriver.support.select import Select
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
# driver.minimize_window()
sleep(2)
driver.maximize_window()
sleep(2)
def login():
    driver.get("http://localhost/ranzhi/www/")
    sleep(2)
    t = driver.find_element(By.ID,"account")
    # #动作链表示可以连续执行的动作,每个动作用 '.'进行连接,最后使用perform()进行结尾
    t.send_keys("admin")
    sleep(2)
    driver.find_element(By.ID,"password").send_keys("123456")
    sleep(2)
    driver.find_element(By.ID,"submit").click()
    sleep(5)
    driver.find_element(By.XPATH,"/html/body/div[1]/div[1]/div/ul[1]/li[8]/button/i").click()
    sleep(2)
    driver.switch_to.frame("iframe-superadmin")
    driver.find_element(By.CSS_SELECTOR,"html.screen-desktop-wide.device-desktop body.m-admin-index div.row.page-content.with-menu div#shortcutBox.container div.row div.col-md-4.col-sm-6 div.shortcut.user a h3").click()
    sleep(2)
    # 添加成员
    # 定位下拉框
    driver.find_element(By.ID, "role").click()
    sleep(1)
    driver.find_element(By.XPATH, "/html/body/div/div/div[2]/div/div[2]/form/table/tbody/tr[5]/td[1]/select/option[9]").click()
    # ele = driver.find_element(By.ID, "role")
    # ele.send_keys("技术支持")
    # 生成下拉框对象
    # select_object = Select(ele)
    # 1.通过 select_by_index() 选择下拉框的值.
    # select_object.select_by_index(8)
    # 2.通过 value 值进行选择:
    # select_object.select_by_value("support")
    # 3.通过选项的文本值进行选择
    # select_object.select_by_visible_text("技术支持")
    sleep(5)
    driver.switch_to.default_content()
    driver.find_element(By.LINK_TEXT,"签退").click()
    sleep(3)
    driver.quit()
if __name__ == '__main__':
    login()